package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import xxl.signals.base.DeluxeSignal;
	import xxl.signals.base.LazySignal;
	import xxl.signals.base.MonoSignal;
	import xxl.signals.base.natives.LazyNativeRelaySignal;
	import xxl.signals.base.natives.NativeMappedSignal;
	import xxl.signals.base.natives.NativeRelaySignal;
	import xxl.signals.base.natives.NativeSignal;
	import xxl.signals.base.natives.sets.NativeSignalSet;
	import xxl.signals.base.OnceSignal;
	import xxl.signals.base.PrioritySignal;
	import xxl.signals.base.Signal;
	import xxl.signals.core.ILazySignal;
	import xxl.signals.core.IOnceSignal;
	import xxl.signals.core.ISignal;
	import xxl.signals.core.natives.INativeDispatcher;
	
	/**
	 * ...
	 * @author XXL
	 */
	public class Main extends Sprite 
	{
		public var abc:int;
		
		protected var ghi:Array;
		
		public function Main() 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		public function set def(value:int):void
		{
			
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			var o:OnceSignal = new OnceSignal(int);
			var s:Signal = new Signal(int, int);
			s.addOnce(fun2);
			s.add(fun3);
			s.dispatch(1000, 0);
			s.dispatch(2000, 100);
			new PrioritySignal();
			new MonoSignal();
			new DeluxeSignal();
			new NativeSignal();
			new NativeRelaySignal();
			var n:INativeDispatcher = new NativeMappedSignal(stage, MouseEvent.CLICK, MouseEvent, int).mapTo(100);
			//n.add(fun2);
			//
			//trace(fun1.length);
			//trace(fun2.length);
			//trace(fun3.length);
			
			new NativeSignalSet(stage);
			var l:LazySignal = new LazySignal(int);
			l.add(fun2);
			l.addOnce(fun3);
			l.dispatch(100);
			l.activate(1);
			trace("------");
			l.dispatch(200);
			l.dispatch(300);
			l.dispatch(400);
			l.dispatch(500);
			l.activate(1);
			trace("------");
			l.dispatch(600);
			l.activate(1000);
			trace("------");
			l.dispatch(700);
			l.activate();
			trace("------");
			l.dispatch(800);
			l.activate();
			trace("------");
			
			this.l = new LazyNativeRelaySignal(stage, KeyboardEvent.KEY_DOWN, KeyboardEvent);
			this.l["add"](function(e:Event):void { trace(e) } );
			//new NativeSignal(stage, MouseEvent.CLICK, MouseEvent).add(clickHandler);
			new NativeMappedSignal(stage, MouseEvent.CLICK, MouseEvent, String, int).mapTo("点击", 7).add(clickHandler2);
		}
		
		private function clickHandler2(str:String, value:int):void 
		{
			trace(str, value);
		}
		
		private function clickHandler(e:Event):void 
		{
			this.l.activate();
		}
		
		private var l:ILazySignal;
		
		private function fun1(v1:int,v2:String,v3:Main):void 
		{
			trace(v1, v2, v3);
		}
		
		private function fun2(v1:int, ...v2):void
		{
			trace("fun2", v1, v2);
			for (var i:int = 0; i < 9000000; i++) 
			{
				var r:int = i;
			}
		}
		
		private function fun3(...v):void
		{
			trace("fun3", v);
		}
		
	}

}